package com.bocai.yuweiwangluo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.bean.MyGameListBean;
import com.bocai.yuweiwangluo.utils.ImageLoaderUtil;
import com.bocai.yuweiwangluo.utils.TimeUtils;
import com.bocai.yuweiwangluo.utils.UrlData;


public class MyGameListAdapter extends BaseAdapter
{
    private MyGameListBean mGameListBean;
    private Context context;
    public MyGameListAdapter(Context context,MyGameListBean mGameListBean)
    {
        this.context=context;
        this.mGameListBean=mGameListBean;
    }
    public void addData(MyGameListBean bean){
        mGameListBean.getData().addAll(bean.getData());
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount()
    {
        return mGameListBean.getData().size();
    }

    @Override
    public Object getItem(int position)
    {
        return mGameListBean.getData().get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_mygame_list,null);
            viewHolder.ivImg=(ImageView)convertView.findViewById(R.id.iv_mygame_img);
            viewHolder.tvName=(TextView)convertView.findViewById(R.id.tv_mygame_name);
            viewHolder.tvDistance=(TextView)convertView.findViewById(R.id.tv_mygame_distance);
            viewHolder.tvAddress=(TextView)convertView.findViewById(R.id.tv_mygame_address);
            viewHolder.tvMoney=(TextView)convertView.findViewById(R.id.tv_mygame_money);
            viewHolder.tvTime=(TextView)convertView.findViewById(R.id.tv_mygame_time);
            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MyGameListBean.Data data=mGameListBean.getData().get(position);
        ImageLoaderUtil.loaderImageDefault(UrlData.IMAGEURL+data.getPic(),viewHolder.ivImg);
        viewHolder.tvName.setText(data.getTitle());
        viewHolder.tvAddress.setText(data.getAddr());
        viewHolder.tvMoney.setText(data.getPrice() + "元/人");
        viewHolder.tvTime.setText(TimeUtils.getTime(Long.parseLong(data.getGame_time())));
        return convertView;
    }


    public class ViewHolder
    {
        ImageView ivImg;
        TextView tvName;
        TextView tvDistance;
        TextView tvAddress;
        TextView tvTime;
        TextView tvMoney;
    }
}
